package com.fastloan.jn.mgt.all.table.util;

import com.google.gson.*;

import java.lang.reflect.Type;

/**
 * Created by gelon on 2017/11/2.
 */
public class IntegerAdapter implements JsonSerializer<Integer>,JsonDeserializer<Integer>{
    @Override
    public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        if(json.getAsString().equals("") || json.getAsString().equals("null")){
            return 0 ;
        }
        return json.getAsInt();
    }

    @Override
    public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
        return new JsonPrimitive(src);
    }
}
